package C046;

/**
 * ClassName: C01
 * Package: C046
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/8 09:21
 * @Version 1.0
 * @Since 1.0
 */
public class C01NumArray {
    public static void main(String[] args) {

    }

    int[] sum;
//    public C01NumArray(int[] nums) {
//        if(nums == null || nums.length == 0) {
//            return;
//        }
//        sum = new int[nums.length];
//        sum[0] = nums[0];
//        for (int i = 1; i < nums.length; i++) {
//            sum[i] = sum[i - 1] + nums[i];
//        }
//    }

    public C01NumArray(int[] nums) {
        if(nums == null || nums.length == 0) {
            return;
        }
        sum = new int[nums.length + 1];
        sum[1] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            sum[i + 1] = sum[i] + nums[i];
        }
    }

    public int sumRange(int left, int right) {
        return sum[right + 1] - sum[left];
    }
}
